package net.csdn.business.kanban.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import net.csdn.business.kanban.api.entity.KanbanField;
import net.csdn.business.kanban.api.mapper.KanbanFieldMapper;
import net.csdn.business.kanban.api.service.KanbanFieldService;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName KanbanServiceImpl
 * @Description TODO
 * @Author liuzhisheng
 * @Date 2023/9/13
 **/
@Service
@RequiredArgsConstructor
public class KanbanFieldServiceImpl extends ServiceImpl<KanbanFieldMapper, KanbanField> implements KanbanFieldService {
    private final KanbanFieldMapper kanbanFieldMapper;

    @Override
    public boolean removeKanbanFileds(String kanbanId) {
        QueryWrapper<KanbanField> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanField::getKanbanId,kanbanId);
        return kanbanFieldMapper.delete(queryWrapper) > 0 ? true : false;
    }

    @Override
    public List<KanbanField> getFieldsByKbId(String kanbanId) {
        QueryWrapper<KanbanField> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanField::getKanbanId,kanbanId);
        return kanbanFieldMapper.selectList(queryWrapper);
    }

    @Override
    public Boolean isExistField(String kanbanId, String fieldId) {
        QueryWrapper<KanbanField> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanField::getKanbanId,kanbanId).eq(KanbanField::getId,fieldId);
        return kanbanFieldMapper.selectCount(queryWrapper) > 0 ? true : false;
    }

    @Override
    public long countField(String kanbanId) {
        QueryWrapper<KanbanField> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(KanbanField::getKanbanId,kanbanId);
        return kanbanFieldMapper.selectCount(queryWrapper);
    }
}
